{include file='public:header-css'/}
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        {include file='public:left-menu'/}
        <!--End 左侧导航-->
        <!--头部信息-->
        {include file='public:nav-header' title="权限管理" subTitle="权限资源列表"/}
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar">
                                <div class="toolbar-btn-action">
                                    <a class="btn btn-label btn-theme" href="{:url('Admin/add_edit_right')}"><label><i
                                            class="mdi mdi-checkbox-marked-circle-outline"></i></label> 添加权限</a>
                                    <a class="btn btn-label btn-danger" onclick="handel()"><label><i
                                            class="mdi mdi-delete"></i></label> 批量删除</a>
                                </div>
                                <div class="card-toolbar-center">
                                    <a href="" class="table-btn btn-dark"><i class="mdi mdi-replay"></i></a>
                                    <button class="table-btn btn-theme">共{$list->total()}条记录
                                        当前第{$list->currentPage()}页
                                    </button>
                                </div>
                                <form class="table-form" method="post" action="">
                                    <div class="table-form-group">
                                        <select name="group" class="input-group-select">
                                            <option value="">所属分组</option>
                                            {volist name="$modules" id="module"}
                                            <option value="{$key}" {if $Request.param.group==$key}selected{/if}>{$module}</option>
                                            {/volist}
                                        </select>
                                        <input type="text" value="{$Request.param.keyword}" name="keyword"
                                               placeholder="查询名称">
                                        <button class="btn btn-default" type="submit">搜索</button>
                                    </div>
                                </form>
                            </div>
                            <div class="card-body">
                                <table class="table table-bordered table-striped table-hover">
                                    <thead>
                                    <tr>
                                        <th style="width: 50px">
                                            <label class="table-checkbox">
                                                <input type="checkbox" id="check-all"><span></span>
                                            </label>
                                        </th>
                                        <th style="width: 100px">操作</th>
                                        <th style="width: 120px">ID</th>
                                        <th style="width: 120px">名称</th>
                                        <th style="width: 120px">所属分组</th>
                                        <th>权限码</th>
                                        <th>是否显示</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {if $list->isEmpty()}
                                    <tr>
                                        <td class="no-data" colspan="50">
                                            <i class="mdi mdi-alert-decagram"></i>没有符合条件的记录
                                        </td>
                                    </tr>
                                    {else/}
                                    {volist name="$list" id="vo"}
                                    <tr>
                                        <td>
                                            <label class="table-checkbox">
                                                <input type="checkbox" class="checkbox"
                                                       value="{$vo[$vo.pk]}"><span></span>
                                            </label>
                                        </td>
                                        <td>
                                            <a class="table-btn btn-theme" href="{:url('Admin/add_edit_right',['id'=>$vo[$vo.pk]])}"><i class="mdi mdi-pencil"></i>编辑</a>
                                        </td>
                                        <td>{$vo[$vo.pk]}</td>
                                        <td>{$vo.name}</td>
                                        <td>{$modules[$vo.group]}</td>
                                        <td style="width: 800px">
                                            <div style="width: 900px;overflow:hidden;text-overflow: ellipsis;">{$vo.right}</div>
                                        </td>
                                        <td><span data-id="{$vo[$vo.pk]}"
                                                  class="open mdi {$vo.open==1 ? 'text-success mdi-checkbox-marked-circle-outline' : 'text-red mdi-close-circle-outline'}"> {$vo.open_text}</span>
                                        </td>
                                    </tr>
                                    {/volist}
                                    {/if}
                                    </tbody>
                                </table>
                                <!--分页-->
                                <div class="page">
                                    {$page|raw}
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $('.open').on('click', function () {
            if ($(this).hasClass('text-success')) {
                var open = 0;
                var add = 'text-red mdi-close-circle-outline';
                var remove = 'text-success mdi-checkbox-marked-circle-outline';
                var text = ' 否';
            } else {
                var open = 1;
                var add = 'text-success mdi-checkbox-marked-circle-outline';
                var remove = 'text-red mdi-close-circle-outline';
                var text = ' 是';
            }
            var id = $(this).attr('data-id');
            var obj = $(this);
            changeTableVal('system_menu', 'open', id, open, function (res) {
                if (res.code == 1) {
                    obj.removeClass(remove).addClass(add).text(text);
                }
            });
        });
    });
    function handel() {
        var checkbox = $('.checkbox:checked');
        if (checkbox.length == 0) {
            showErrorMsg("请选择数据");
            return
        }
        var ids = [];
        $.each(checkbox, function (index, item) {
            ids.push(item.value)
        });
        var text = "确认操作?";
        showConfirm(text, function () {
            var url = "{:url('Index/public_delete')}";
            var data = {'ids': ids,'table':'system_menu'};
            public_ajax(url, data, function (res) {
                if (res.code==1){
                    showSuccessMsg(res.msg,function () {
                        location.reload()
                    })
                }else {
                    showErrorMsg(res.msg);
                }
            })
        })
    }
</script>
</body>
</html>
